﻿using System.Collections.Generic;

namespace PlusPlusPaint
{
    /// <summary>
    /// Represents an object that is ready to be written out to a file.
    /// </summary>
    public class SerializedObject
    {
        public readonly string Name;
        public readonly IList<int> UnnamedInts;
        public readonly IList<string> UnnamedStrings;
        public readonly IList<SerializedObject> UnnamedSubobjects;
        public readonly IDictionary<string, int> NamedInts;
        public readonly IDictionary<string, string> NamedStrings;
        public readonly IDictionary<string, SerializedObject> NamedSubobjects;

        public SerializedObject(
            string name,
            IList<int> unnamedInts = null,
            IList<string> unnamedStrings = null,
            IList<SerializedObject> unnamedSubobjects = null,
            IDictionary<string, int> namedInts = null,
            IDictionary<string, string> namedStrings = null,
            IDictionary<string, SerializedObject> namedSubobjects = null
        )
        {
            this.Name = name ?? "";
            this.UnnamedInts = unnamedInts ?? new List<int>();
            this.UnnamedStrings = unnamedStrings ?? new List<string>();
            this.UnnamedSubobjects = unnamedSubobjects ?? new List<SerializedObject>();
            this.NamedInts = namedInts ?? new Dictionary<string, int>();
            this.NamedStrings = namedStrings ?? new Dictionary<string, string>();
            this.NamedSubobjects = namedSubobjects ?? new Dictionary<string, SerializedObject>();
        }

        public SerializedObject CloneWithName(string newName)
        {
            return new SerializedObject(
                newName,
                this.UnnamedInts,
                this.UnnamedStrings,
                this.UnnamedSubobjects,
                this.NamedInts,
                this.NamedStrings,
                this.NamedSubobjects
            );
        }
    }
}
